package com.skyline.user.service.impl;

import java.util.Date;

import org.apache.commons.codec.digest.DigestUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.skyline.user.dao.PersonalInfoDao;
import com.skyline.user.model.User;
import com.skyline.user.service.PersonalInfoService;
import com.skyline.user.type.Sex;

@Service("personalInfoService")
public class PersonalInfoServiceImpl implements PersonalInfoService {
	@Autowired
	private PersonalInfoDao personalInfoDao;

	@Override
	public void modifyBasicInfo(Long userid, String name, String nickName, Date birthday, Sex sex,
			String province, String city, String country, String siteId, String job,
			String graduateSchool) {
		personalInfoDao.updateBasicInfo(userid, name, nickName, birthday, sex, province, city,
				country, siteId, job, graduateSchool);
	}

	@Override
	public void modifyCommunicationInfo(Long userid, String mobilephone, String msn, String qq) {
		personalInfoDao.updateCommunicationInfo(userid, mobilephone, msn, qq);
	}

	@Override
	public User getPersonInfoByUserID(Long userid) {
		return personalInfoDao.queryPersonInfoByUserID(userid);
	}

	@Override
	public User getPersonInfoByEmail(String email) {
		return personalInfoDao.queryPersonInfoByEmail(email);
	}

	@Override
	public Boolean checkPassword(Long userId, String password) {
		password = String.valueOf(DigestUtils.md5Hex(password));
		User user = personalInfoDao.queryPersonInfoByIdAndPassword(userId, password);
		if (user == null)
			return false;
		return true;
	}

	@Override
	public void updatePassword(Long userId, String password) {
		password = String.valueOf(DigestUtils.md5Hex(password));
		personalInfoDao.updatePasswordInfo(userId, password);

	}

	@Override
	public void changeUserPortrait(Long userId, String portraitFile) {
		personalInfoDao.updateUserPortrait(userId, portraitFile);
	}

}
